package com.ww.sound_emission.controller;

import com.ww.sound_emission.domain.Users;
import com.ww.sound_emission.service.UsersService;
import com.ww.sound_emission.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UsersService userService;

    // 获取用户信息
    @GetMapping("/{id}")
    public Result<Users> getUserById(@PathVariable Long id) {
        Users user = userService.getById(id);
        return Result.success(user);
    }

    // 更新用户信息
    @PutMapping("/{id}")
    public Result<String> updateUser(@PathVariable Long id, @RequestBody Users user) {
        // user.setId(Math.toIntExact(id));
        userService.updateById(user);
        return Result.success("用户信息更新成功");
    }

    // 删除用户
    @DeleteMapping("/{id}")
    public Result<String> deleteUser(@PathVariable Long id) {
        userService.removeById(id);
        return Result.success("用户删除成功");
    }
}